<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单统计</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script>
    <style>
        body {
            background-color: #f8f9fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

       .container {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 30px;
            margin-top: 50px;
        }

        h1,
        h2 {
            color: #343a40;
        }

       .chart-container {
            margin-bottom: 30px;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1 class="text-center">订单统计</h1>

        <h2>每个订单的总金额</h2>
        <div class="chart-container">
            <div id="orderAmountChart" style="width: 100%; height: 400px;"></div>
        </div>

        <h2>每个商品的订单金额</h2>
        <div class="chart-container">
            <div id="productOrderAmountChart" style="width: 100%; height: 400px;"></div>
        </div>

        <h2>每个商品被购买的次数</h2>
        <div class="chart-container">
            <div id="productPurchaseCountChart" style="width: 100%; height: 400px;"></div>
        </div>
    </div>

    <script type="text/javascript">
        // 每个订单的总金额
        var orderAmountData = {{ order_amounts_data | tojson }};
        var orderAmountChart = echarts.init(document.getElementById('orderAmountChart'));
        orderAmountChart.setOption({
            title: {
                text: '每个订单的总金额',
                textStyle: {
                    color: '#343a40'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type:'shadow'
                }
            },
            xAxis: {
                type: 'category',
                data: orderAmountData.map(item => item.order_id),
                axisLabel: {
                    color: '#343a40',
                    interval: 0,
                    rotate: 45
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    color: '#343a40'
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: '#dee2e6'
                    }
                }
            },
            series: [{
                data: orderAmountData.map(item => item.total_amount),
                type: 'bar',
                itemStyle: {
                    color: '#007bff'
                }
            }]
        });

        // 每个商品的订单金额
        var productOrderAmountData = {{ product_order_amounts_data | tojson }};
        var productOrderAmountChart = echarts.init(document.getElementById('productOrderAmountChart'));
        productOrderAmountChart.setOption({
            title: {
                text: '每个商品的订单金额',
                textStyle: {
                    color: '#343a40'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type:'shadow'
                }
            },
            xAxis: {
                type: 'category',
                data: productOrderAmountData.map(item => item.product_name),
                axisLabel: {
                    color: '#343a40',
                    interval: 0,
                    rotate: 45
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    color: '#343a40'
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: '#dee2e6'
                    }
                }
            },
            series: [{
                data: productOrderAmountData.map(item => item.total_amount),
                type: 'bar',
                itemStyle: {
                    color: '#28a745'
                }
            }]
        });

        // 每个商品被购买的次数
        var productPurchaseCountData = {{ product_purchase_count_data | tojson }};
        var productPurchaseCountChart = echarts.init(document.getElementById('productPurchaseCountChart'));
        productPurchaseCountChart.setOption({
            title: {
                text: '每个商品被购买的次数',
                textStyle: {
                    color: '#343a40'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type:'shadow'
                }
            },
            xAxis: {
                type: 'category',
                data: productPurchaseCountData.map(item => item.product_name),
                axisLabel: {
                    color: '#343a40',
                    interval: 0,
                    rotate: 45
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    color: '#343a40'
                },
                axisLine: {
                    lineStyle: {
                        color: '#343a40'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: '#dee2e6'
                    }
                }
            },
            series: [{
                data: productPurchaseCountData.map(item => item.purchase_count),
                type: 'bar',
                itemStyle: {
                    color: '#dc3545'
                }
            }]
        });
    </script>
</body>

</html>